﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using BrainTechLLC.Silverlight.Controls;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class ShowLocationEdges : BaseDataVisualizer, ICollectionDataVisualizer
    {
        public override void SetVisualizedData(DataVisualizer vis, object o) { LocationEdges = o as ObservableCollection<LocationEdge>; base.SetVisualizedData(vis, o); }
        public Type VisualizeType { get { return typeof(Ability); } }
        public string VisualizerName { get { return "ShowLocationEdgesControl"; } }

        public static readonly DependencyProperty LocationEdgesProperty = DependencyProperty.Register(
            "LocationEdges", typeof(ObservableCollection<LocationEdge>), typeof(ShowLocationEdges), new PropertyMetadata(null, new PropertyChangedCallback(LocationEdgesChanged)));

        public static void HandleChange<T2>(DependencyObject d, DependencyPropertyChangedEventArgs e, Action<ShowLocationEdges, T2> action)
        {
            d.HandleChange<ShowLocationEdges, T2>(e, action, (t) => t.UpdateBindings());
        }

        public ObservableCollection<LocationEdge> LocationEdges
        {
            get { return (ObservableCollection<LocationEdge>)GetValue(LocationEdgesProperty); }
            set { SetValue(LocationEdgesProperty, value); }
        }

        private static void LocationEdgesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            HandleChange<ObservableCollection<LocationEdge>>(d, e, (t, val) => t.LocationEdges = val);
        }

        public override void UpdateBindings()
        {
            lstLocationEdges.ItemsSource = LocationEdges;
        }

        public ShowLocationEdges()
        {
            InitializeComponent();
        }

        public override string TitleText
        {
            get
            {
                return string.Format("{0} LocationEdges ({1})", LocationEdges.Count, LocationEdges.BuildList((a) => a.Direction.ToString()).MaxLength(30, true));
            }
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement t = sender as FrameworkElement;
            t.StretchListBox();
        }
    }
}